package Controller;

import java.io.UnsupportedEncodingException;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import Service.ScheduleService;

@Controller
public class ScheduleController {
    
	@Resource(name = "scheduleService")
	private ScheduleService scheduleService;
	public ScheduleService getScheduleService() {
		return scheduleService;
	}
	public void setScheduleService(ScheduleService scheduleService) {
		this.scheduleService = scheduleService;
	}
	public ScheduleController() {
		// TODO Auto-generated constructor stub
	}
	
	@RequestMapping("/springs")
	@ResponseBody
	public String testsprings(){
		
		return "Life Springs From Sorrow and Pain.";
	}
	
	//自动生成赛程表存到数据库中
	@RequestMapping("/schedule")
	@ResponseBody
	public String createschedule(){
		
		String string = scheduleService.createschedule();
		return "1";
	}
	
	//datagrid查赛程表数据库
	@RequestMapping("/showvs")
	@ResponseBody
	public String show(String round,String teamleft,String teamright,String time,String page,String rows,HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
		
		request.setCharacterEncoding("UTF-8"); 
		response.setCharacterEncoding("UTF-8"); 
		response.setContentType("text/html;charset=utf-8");
		
		//name = new String(name.getBytes("ISO-8859-1"), "utf-8");
		//content = new String(content.getBytes("ISO-8859-1"), "utf-8");
		
		System.out.println("round "+round);
		System.out.println("teamleft "+teamleft);
		System.out.println("teamright "+teamright);
		System.out.println("time "+time);
		System.out.println("page "+page);
		System.out.println("rows "+rows);
		String string = scheduleService.show(round, teamleft, teamright,time, page,rows);
		return string;
	}
	
	//用于条件查找赛程表
	@RequestMapping("/list")
	@ResponseBody
	public String list(String round,String teamleft,String teamright,String time,String page,String rows,HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
		
		request.setCharacterEncoding("UTF-8"); 
		response.setCharacterEncoding("UTF-8"); 
		response.setContentType("text/html;charset=utf-8");
		
		//name = new String(name.getBytes("ISO-8859-1"), "utf-8");
		//content = new String(content.getBytes("ISO-8859-1"), "utf-8");
		
		System.out.println("round "+round);
		System.out.println("teamleft "+teamleft);
		System.out.println("teamright "+teamright);
		System.out.println("time "+time);
		System.out.println("page "+page);
		System.out.println("rows "+rows);
		String string = scheduleService.list(page,rows);
		return string;
	}
	
	//获得单个team的赛程表
	@RequestMapping("/union")
	@ResponseBody
	public String union(String team,String page,String rows,HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
		
		request.setCharacterEncoding("UTF-8"); 
		response.setCharacterEncoding("UTF-8"); 
		response.setContentType("text/html;charset=utf-8");
		
		//name = new String(name.getBytes("ISO-8859-1"), "utf-8");
		//content = new String(content.getBytes("ISO-8859-1"), "utf-8");
		
		
		System.out.println("team "+team);
		System.out.println("page "+page);
		System.out.println("rows "+rows);
		String string = scheduleService.union(team,page,rows);
		return string;
	}
	
	//获取球队信息
	@RequestMapping("/euroteam")
	@ResponseBody
	public String euro(HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
		
		request.setCharacterEncoding("UTF-8"); 
		response.setCharacterEncoding("UTF-8"); 
		response.setContentType("text/html;charset=utf-8");
		
		//name = new String(name.getBytes("ISO-8859-1"), "utf-8");
		//content = new String(content.getBytes("ISO-8859-1"), "utf-8");
		
		
		
		String string = scheduleService.euro();
		return string;
	}
	
	//获得一组对战表
	@RequestMapping("/vsone")
	@ResponseBody
	public String vsone(String teamleft,String teamright,HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
		
		request.setCharacterEncoding("UTF-8"); 
		response.setCharacterEncoding("UTF-8"); 
		response.setContentType("text/html;charset=utf-8");
		
		//name = new String(name.getBytes("ISO-8859-1"), "utf-8");
		//content = new String(content.getBytes("ISO-8859-1"), "utf-8");
		
		
		System.out.println("teamleft "+teamleft);
		System.out.println("teamright "+teamright);
		
		String string = scheduleService.vsbyone(teamleft, teamright);
		return string;
	}
	
	//获得某一轮赛程表
	@RequestMapping("/round")
	@ResponseBody
	public String round(String round,HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
		
		request.setCharacterEncoding("UTF-8"); 
		response.setCharacterEncoding("UTF-8"); 
		response.setContentType("text/html;charset=utf-8");
		
		//name = new String(name.getBytes("ISO-8859-1"), "utf-8");
		//content = new String(content.getBytes("ISO-8859-1"), "utf-8");
		
		
		
		
		String string = scheduleService.round(round);
		return string;
	}
	
	//获取轮次数
	@RequestMapping("/ground")
	@ResponseBody
	public String ground(HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
		
		request.setCharacterEncoding("UTF-8"); 
		response.setCharacterEncoding("UTF-8"); 
		response.setContentType("text/html;charset=utf-8");
		
		//name = new String(name.getBytes("ISO-8859-1"), "utf-8");
		//content = new String(content.getBytes("ISO-8859-1"), "utf-8");
		
		
		
		String string = scheduleService.ground();
		return string;
	}


}
